﻿<%@ Page Title="Ebiz - Claims" Language="C#" ValidateRequest="false" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Claims.aspx.cs" Inherits="Ebiz.Claims" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="css/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery.uploadify.js" type="text/javascript"></script>
    <script src="js/claim.js" type="text/javascript"></script>
     <style type="text/css">
      
        .progress-label {
            position: absolute;
            left: 40%;
            top: 15px;
            text-shadow: 1px 1px 0 #fff;
            font-size:smaller;
        }
    </style>
    <script type="text/javascript">
    
    var Form1 = "<%= Form1.ClientID %>";
    var fileUpCtrl = "<%= fileUpCtrl.ClientID %>";
    var result = '';
    var rowCount = 0;
    var currRow = 1;
    var currValue = 0;
    

    function DownloadFile() {
        if (document.cookie != '') {
            if (document.cookie.split("iddata").length > 0) {
                var dataInput = document.createElement("input");
                dataInput.setAttribute("name", 'data');
                dataInput.setAttribute("value", document.cookie);
                var myForm = document.createElement("form");
                myForm.method = 'post';
                myForm.action = '<%= GetVirtualPath() %>' + "DownloadClaims.aspx",
                myForm.appendChild(dataInput);
                document.body.appendChild(myForm);
                myForm.submit();
                document.body.removeChild(myForm);
            }
            else {
                alert("No data can be downloaded");
            }
        }
        else {
            alert("No data can be downloaded");
            location.reload(true);
        }
   }

   function CheckPerRow(rowNumber) {
       jQuery.ajax({
           type: "POST",
           url: '<%= GetVirtualPath() %>' + "PageHandler.aspx/CheckPerRow",
           contentType: "application/json; charset=utf-8",
           data: "{ rowNumber :'" + rowNumber + "', path : '" + escape(document.cookie) + "'}", //JSON.stringify(DTO),
           dataType: "json",
           async: false,
           success: function(response) {
               var msg = response.d;
               result = msg;
               if (result != 'fail') {
                  document.cookie = "iddata=" + result;
               }
               $("#sampleProgressBar").progressbar('value', $("#sampleProgressBar").progressbar('value') + 100 / rowCount);
           },
           error: function(xhr, ajaxOptions, thrownError) {
               alert(xhr.responseText);
           }
       })
   }


   function ProcessChecking() {
       var progressLabel = $(".progress-label");

       var progressBar = $("#sampleProgressBar")
                .progressbar({
                    value: 0,
                    change: function() {
                            progressLabel.text('Processing ' + currRow + ' row');
                        },
                     complete: function() {
                            progressLabel.text("Complete!");
                        }
                });

       var progressDialog = $("#progressDialog")
                .dialog({ autoOpen: true,
                    modal: true,
                    title: "Please wait",
                    resizable: false,
                    draggable: false,
                    dialogClass: "noCloseBtn",
                    width: 600,
                    beforeClose: function() {
                        if ($("#sampleProgressBar").progressbar('value') != 100)
                            return false;
                    }
                })

                var progressUpdater;
                var rowCountData = 0;
                var filename = arrFiles[0].FileName;

                jQuery.ajax({
                    type: "POST",
                    url: '<%= GetVirtualPath() %>' + "PageHandler.aspx/GetExcelData",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: "{ FileName :'" + filename + "'}", 
                    async: false,
                    success: function(response) {
                        rowCountData = response.d;
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(xhr.responseText);
                    }
                })

                rowCount = rowCountData;
                setTimeout(function() {
                    $("#sampleProgressBar").progressbar('value', 0);
                    progressUpdater = setInterval(function() {
                        if ($("#sampleProgressBar").progressbar('value') == 100) {
                            $("#progressDialog").dialog("close");
                            $('#progressTrigger').focus();

                            DownloadFile();
                            location.reload(true);
                        }
                        else {
                            currValue = $("#sampleProgressBar").progressbar('value') * rowCount / rowCount;
                            CheckPerRow(currRow);
                            currRow++;
                        }
                    }, 100);
                }, rowCount);
   }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" runat="server">
    <h3>Claims</h3>
    <form id="Form1" runat="server">    
            <div style="margin:0 auto; position:relative; width:100%;">
            <table id="tblInfo" align="left" cellpadding="6" cellspacing="0" style="margin-bottom:30px;font-size: 12px; font-family: Arial;">
                <tr>
                    <td style="text-align:left;padding:5px 0;width:300px;">Upload & Checking File</td>
                    <td>:</td>
                    <td style="text-align:left;width:210px;">
                         <asp:FileUpload ID="fileUpCtrl" runat="server" Font-Size="12px" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                       <asp:GridView ID="gridviewResult"  HeaderStyle-BackColor="#378de5" HeaderStyle-ForeColor="#FFFFFF" 
                        runat="server" AllowPaging="true" OnSorting="gridviewResult_Sorting" AllowSorting="true" onpageindexchanging="gridviewResult_PageIndexChanging">
                         </asp:GridView>
                        <asp:HiddenField ID="gridViewHiddenScript" runat="server" />
                        <asp:HiddenField ID="idDataHidden" runat="server" />
                    </td>
                </tr>
                <tr><td colspan="3">&nbsp;</td></tr>
                <tr>
                    <td colspan="3" style="text-align:left;">
                        <input type="button" id="btnDwl" onclick="DownloadFile()" class="btnSmall" value="Download" />
                    </td>
                </tr>
                <tr><td colspan="3" style="color:Red;"><br /><%= ErrMsg %></td></tr>
            </table>
</div>
<div id="progressbar">
    <div class="ui-helper-clearfix">
        <div id="progressDialog">
            <div id='sampleProgressBar' class="demoWidget">
                <div class='progress-label'>Loading</div>
            </div>
            <br />
            <div id='siteId'>
            </div>
        </div>
    </div>
</div>
    </form>
</asp:Content>